from django.db import models
from datetime import datetime
# Create your models here.


# class Update(models.Model):  #修改密码
#     username=models.CharField(max_length=20)
#     password=models.CharField(max_length=20)
#     newpassword=models.CharField(max_length=20)
#     conpassword=models.CharField(max_length=20) #确认密码

class UserProfile(models.Model): #用户表
    username=models.CharField(verbose_name='用户名',max_length=50,null=False)
    password=models.CharField(verbose_name='密码',max_length=50,null=False)
    phone=models.CharField(verbose_name='手机号',max_length=11)
    email=models.EmailField(verbose_name='邮箱',max_length=50,null=False)
    code = models.CharField(max_length=20, verbose_name='验证码')


# class User_address(models.Model):#用户地址
#     address_id=models.AutoField(verbose_name='地址id',primary_key=True)
#     consignee_name=models.CharField(verbose_name='收货人姓名',max_length=50)
#     consignee_phone=models.CharField(verbose_name='收货人手机号',max_length=11)
#     consignee_state=models.CharField(verbose_name='收货人省份',max_length=50)
#     consignee_city=models.CharField(verbose_name='收货人城市',max_length=50)
#     consignee_county=models.CharField(verbose_name='收货人县/市',max_length=50)
#     consignee_address=models.CharField(verbose_name='收货人地址',max_length=50)
#     consignee_zipcode=models.CharField(verbose_name='收货人邮政编码',max_length=50)
#     create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True, null=False)
#     update_time = models.DateTimeField(verbose_name='修改时间', auto_now=True, null=False)
#     user_id=models.ForeignKey(User,on_delete=models.CASCADE) #外键用户id
#
# class Article_sort(models.Model):  # 商品分类
#     sort_name = models.CharField(verbose_name='分类名', max_length=50)
#     create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True, null=False)
#     update_time = models.DateTimeField(verbose_name='修改时间', auto_now=True, null=False)
#
class Article(models.Model):#商品表
    COMN=(
        ("0","上架"),
        ("1","下架"),
        ("2","没货"),
    )
    product_id=models.AutoField(verbose_name='商品id/编号',primary_key=True)
    article_title=models.CharField(verbose_name='商品标题',max_length=10)
    article_price=models.IntegerField(verbose_name='商品价格')
    article_PCS=models.IntegerField(verbose_name='库存数量')
    article_img=models.URLField(verbose_name='商品图片')
    #their_sort=models.ForeignKey(Article_sort,on_delete=models.CASCADE)
    article_state=models.CharField(verbose_name='商品状态',max_length=1,choices=COMN)
#     create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True, null=False)
#     update_time = models.DateTimeField(verbose_name='修改时间', auto_now=True, null=False)

    def to_dict(self):
        return {"title":self.article_title,"price":self.article_price,"PCS":self.article_PCS}


# 邮箱验证类

class EmailVerifyRecord(models.Model):
    """邮箱激活码"""
    code=models.CharField(max_length=20,verbose_name='验证码')
    email=models.EmailField(max_length=50,verbose_name='邮箱')
    send_type=models.CharField(verbose_name='验证码类型',choices=(('register','注册'),('forget','忘记密码')),
                               max_length=20)
    send_time=models.DateTimeField(verbose_name='发送时间',default=datetime.now)
    class Meta:
        verbose_name='邮箱验证码'
        verbose_name_plural=verbose_name
    def __str__(self):
        return '{0}({1})'.format(self.code,self.email)





